<template>
	<view class="QS container pre-hover" hover-class="hover-scale" :hover-start-time="0" @tap="_click">
		<block v-if="listItem.type == 'ad'">
			<swiper class="ad-swiper" :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000">
				<swiper-item v-for="(item, index) in (listItem.banners || [])" :key="index">
					<view>
						<image :src="item.imgUrl || item || ''" mode="aspectFill" class="ad-image"></image>
					</view>
				</swiper-item>
			</swiper>
		</block>
		<block v-else>
			<view class="image-box">
				<image 
				:src="listItem.goodsThumbnail || ''"
				 mode="aspectFill" 
				 class="image"
				 :class="{ sellClear: listItem.remainStock == 0, isOvered: listItem.isOvered }"
				 @load="imageLoaded"></image>
				 <view class="topRightBox flex_row_c_c">
				 	<text class="QS-text mini-xx color_ffffff display_block" style="line-height: 24rpx;">已售{{listItem.saleCount || 0}}</text>
				 </view>
			</view>
			<view class="content">
				<text class="QS-text mini weight color_000000 text-overflow_ellipsis_line_2">{{listItem.goodsName}}</text>
				<view class="flex_row_between_c margin-top-rpx_15">
					<view class="flex_row_none_c">
						<view class="text-tabel-cell-bottom">
							<text class="QS-text mini-xxx price-weight price-color">￥</text>
							<text class="QS-text large-36rpx price-weight price-color">{{listItem.salePrice || 0}}</text>
						</view>
						<block v-if="Number(listItem.price)">
							<QS-P width="15rpx"></QS-P>
							<text class="QS-text mini-x color_BBBBBB text-decoration_line-through">￥{{listItem.price || 0}}</text>
						</block>
					</view>
					<!-- <image src="/static/image/cart.png" mode="aspectFill" class="dyc-img-cart"></image> -->
				</view>
			</view>
		</block>
	</view>
</template>

<script>
	export default {
		props: {
			listItem: {
				type: [Object, String, Number, Array],
				default: () => {
					return {}
				}
			},
			type: {
				type: String,
				default: ''
			}
		},
		data() {
			return {
				imgShow: false
			}
		},
		methods: {
			_click() {
				console.log(this.listItem);
				if(this.listItem.type == 'ad') return;
				uni.$qs.navigateTo('product.common.detail', { id: this.listItem.goodsId })
			},
			imageLoaded(e) {
				this.$emit('imgLoaded')
			}
		}
	}
</script>

<style scoped lang="scss">
	.container {
		/* #ifndef APP-NVUE */
		width: 100%;
		display: flex;
		/* #endif */
		flex-direction: column;
		border-radius: 10rpx;
		overflow: hidden;
		// padding: 15rpx;
		background-color: #fff;
	}

	.list-item {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		width: 330rpx;
		margin-left: 12px;
		margin-right: 12px;
		margin-top: 12px;
		/* padding: 20px; */
		background-color: #fff;
		border-radius: 5px;
		flex-direction: column;
		border-radius: 20rpx;
		overflow: hidden;
	}
	
	.ad-swiper{
		width: 100%;
		height: 600rpx;
		border-radius: 10rpx;
		overflow: hidden;
	}
	
	.ad-image {
		width: 100%;
		height: 600rpx;
		background-color: #F2F2F2;
		border-radius: 10rpx;
	}

	.image-box {
		// position: relative;
		// width: 100%;
		width: 100%;
		position: relative;
		height: 0;
		padding-top: 100%;
	}

	.image {
		// border-top-left-radius: 10rpx;
		// border-top-right-radius: 10rpx;
		// width: 100%;
		position: absolute;
		top: 0;
		left: 0;
		height: 100%;
		width: 100%;
		border-top-left-radius: 10rpx;
		border-top-right-radius: 10rpx;
		transition: opacity .3s;
		background-color: #F2F2F2;
	}

	.image-box-text {
		position: absolute;
		left: 10rpx;
		bottom: 10rpx;
		font-size: 28rpx;
		color: white;
		padding: 10rpx;
		background-color: rgba(0, 0, 0, .6);
	}
	
	.topRightBox {
		position: absolute;
		top: 0;
		right: 0;
		padding: 8rpx 14rpx;
		border-bottom-left-radius: 8rpx;
		border-top-right-radius: 8rpx;
		background-color: rgba(0, 0, 0, .15);
	}

	.content {
		padding: 18rpx 20rpx;
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: column;
	}

	.title-image {
		height: 40rpx;
		width: 40rpx;
		border-radius: 50%;
	}
</style>
